﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>后台登录</title>
    <link rel="icon" href="images/favicon.ico">
    <link href="css/login.css" type="text/css" rel="stylesheet">

    <script src="js/jquery-3.3.1.js"></script> <!-- 你必须先引入jQuery1.8或以上版本 -->
    <script src="layui/layui.all.js"></script>
</head>
<body>
<div class="login">
    <div class="message">成都文理学院考试系统临时登录111</div>
    <div id="darkbannerwrap"></div>
    <form id="jump" method="post" action="loginSuccess.do">
        <input id="account" name="account" placeholder="账号" required="" type="text">
        <hr class="hr15">
        <input id="validate" name="validate" style="width:50%" placeholder="验证码" required="" type="text">
        <label style="position:relative;display:inline-block;height:50px"><img style="position: absolute;top:26px;left:10px;height:80%" type="image" src="authCode.do" id="codeImage" onclick="chageCode()" title="图片看不清？点击重新得到验证码"
                    style="cursor:pointer;"/>

        </label>
        <hr class="hr15">
        <!--这里img标签的src属性的值为后台实现图片验证码方法的请求地址-->

        <input id="submit" value="登录" style="width:100%;" type="button">
        <hr class="hr20">
        <!-- 帮助 <a onClick="alert('请联系管理员')">忘记密码</a> -->
    </form>
</div>

<script>
    // layer.config({
    //     offset:"150px"
    // })
    function chageCode() {
        $('#codeImage').attr('src', 'authCode.do?abc=' + Math.random());//链接后添加Math.random，确保每次产生新的验证码，避免缓存问题。
    }

    $("#submit").click(function () {
        var account = $("#account").val();
        var validate = $("#validate").val();

        switch (true) {
            // case account == null || account == "":
            //         layer.msg('账号不能为空！');
            //     break;
            // case validate == null || validate == "":
            //         layer.msg('验证码不能为空！')
            //     break;
            default:
                $.post(
                    "validate.do",
                    {"value": validate},
                    function (res) {
                       // alert(res)
                        if (res == 1) {
                            $.get(
                                "login.do",
                                {"token": account},
                                function (res) {
                                    console.log(res)
                                    if (res == "jsonCallBackTest(10)") {
                                     window.location.href="loginSuccess.do?token="+account;
                                     //window.location.href=projectName+"/exam/exam.html?token="+account;
                                    } else {
                                        layer.msg('非法用户');
                                        $("#codeImage").trigger("click");
                                    }
                                }
                            );
                        } else {
                            layer.msg('验证码错误');
                            //刷新验证码图片
                            $("#codeImage").trigger("click");
                        }
                    }
                );
        }
    });
</script>
</body>
</html>